using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;
using Ent.Voice;

public partial class Controls_Login : System.Web.UI.UserControl
{
    public string UserNameControl
    {
        get { return txtUsername.ClientID; }
    }
    public Controls_Login()
    {
        this.PreRender += new EventHandler(Controls_Login_PreRender);
    }

    void Controls_Login_PreRender(object sender, EventArgs e)
    {
         lblUsername.Text = ResourceHelper.Get("LBL_UserName");
         lblPassword.Text = ResourceHelper.Get("LBL_Password");
         lblLogin.Text = ResourceHelper.Get("LBL_Login");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnLogin.CausesValidation = false;
            btnLogin.Attributes.Add("onmouseover", "this.src='" + ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/loginh.gif'");
            btnLogin.Attributes.Add("onmouseout", "this.src='" + ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/login.gif'");
        }
    }
    protected void btnLogin_Click(object sender, ImageClickEventArgs e)
    {
        UserLogin ul = User.DoLogin(txtUsername.Text, txtPassword.Text);
        if(ul.Authenticated==Authentication.Inactive)
            Response.Redirect(ConfigurationManager.AppSettings["BaseUrl"] + "/DoLogin.aspx?msg=" + ResourceHelper.Get("MSG_InactiveUser"));
        else if (ul.Authenticated == Authentication.InvalidIDPassword)
            Response.Redirect(ConfigurationManager.AppSettings["BaseUrl"] + "/DoLogin.aspx?msg=" + ResourceHelper.Get("MSG_InvalidLogin"));
        else
        {
            Session["USERID"] = ul.Details.UserID;
            Session["FNAME"] = ul.Details.FName;
            Session["LNAME"] = ul.Details.LName;
            Session["LANG"] = ul.Details.Language;
            Session["EMAIL"] = ul.Details.Email;
            Session["ISADMIN"] = ul.Details.IsAdmin;
            if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                Response.Redirect(HttpUtility.UrlDecode(Request.QueryString["url"]));
            else
                Response.Redirect(ConfigurationManager.AppSettings["BaseUrl"] + "/Member/Home.aspx");
        }
    }
}
